package com.xywh.micro_warehousing.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.xywh.micro_warehousing.R;
import com.xywh.micro_warehousing.di.component.DaggerPickingDetailsComponent;
import com.xywh.micro_warehousing.di.module.PickingDetailsModule;
import com.xywh.micro_warehousing.mvp.contract.PickingDetailsContract;
import com.xywh.micro_warehousing.mvp.presenter.PickingDetailsPresenter;
import com.xywh.micro_warehousing.mvp.ui.entity.PickingDetails;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.jessyan.armscomponent.commonres.utils.ToolbarUtils;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;

import static com.jess.arms.utils.Preconditions.checkNotNull;


@Route(path = RouterHub.ACTIVITY_PICKING_DETAILS)
public class PickingDetailsActivity extends BaseActivity<PickingDetailsPresenter> implements PickingDetailsContract.View {


    @BindView(R.id.img_head)
    ImageView imgHead;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_quantity)
    TextView tvQuantity;
    @BindView(R.id.tv_material_info)
    TextView tvMaterialInfo;
    @BindView(R.id.tv_rfid)
    TextView tvRfid;
    @BindView(R.id.tv_use_time)
    TextView tvUseTime;
    @BindView(R.id.tv_return_time)
    TextView tvReturnTime;
    @BindView(R.id.tv_out_location)
    TextView tvOutLocation;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerPickingDetailsComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .pickingDetailsModule(new PickingDetailsModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_picking_details; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        ToolbarUtils.initToolbarTitleBack(this, getString(R.string.activity_picking_details));
        getPickingDetailsData();
    }

    private void getPickingDetailsData() {
        String id = getIntent().getExtras().getString("id");
        HashMap<String, String> map = new HashMap<>();
        map.put("id", id);
        mPresenter.getPickingDetailsData(map);
    }

    @Override
    public void getPickingDetailsDataSuccess(PickingDetails entityData) {

        if (entityData != null) {
            tvTitle.setText(entityData.getUsedSpaceName());
            tvQuantity.setText("-" + entityData.getUseNum());
            tvMaterialInfo.setText(entityData.getMaterial());
            tvRfid.setText(entityData.getRFID());
            tvUseTime.setText(entityData.getUseDateTime());
            tvReturnTime.setText(entityData.getReturnDateTime());
            tvOutLocation.setText(entityData.getUsedSpaceName());
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }
}
